package com.it.security.config;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 自定义认证失败处理器
 */
@Component("customAuthenticationFailureHandler")
public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        //认证失败后响应json数据给前端
//        Result result = Result.build(HttpStatus.UNAUTHORIZED.value(), exception.getMessage());
//        String s = result.toJsonString();
//        response.setContentType("application/json;charset=UTF-8");
//        response.getWriter().write(s);
        System.out.println("认证失败");


    }
}
